﻿using MengXunAppTool.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengXunAppTool.DAL
{
    public class DingTalkDAL
    {
        private Sql3Helper sqlHelper = new Sql3Helper();
        public List<string> GetWorkPlaces()
        {
            List<string> workPlace = new List<string>();
            List<Sql3Helper.t_DD_UserDetail> list = sqlHelper.db.Queryable<Sql3Helper.t_DD_UserDetail>().
                OrderBy(it => it.workPlace).ToList();
            foreach (var item in list)
            {
                if (!workPlace.Contains(item.workPlace)&&!string.IsNullOrEmpty(item.workPlace))
                {
                    workPlace.Add(item.workPlace);
                }
            }
            return workPlace;
        }
        public List<string> GetUserNames(string workPlace)
        {
            List<string> username = new List<string>();
            List<Sql3Helper.t_DD_UserDetail> list = sqlHelper.db.Queryable<Sql3Helper.t_DD_UserDetail>().
                Where(it=>it.workPlace==workPlace).OrderBy(it => it.username).ToList();
            foreach (var item in list)
            {
                if (!username.Contains(item.username)&&!string.IsNullOrEmpty(item.username))
                {
                    username.Add(item.username);
                }
            }
            return username;
        }
        public string GetUserID(string username)
        {
            return  sqlHelper.db.Queryable<Sql3Helper.t_DD_UserDetail>().
                Where(it => it.username == username).First().userid;
        }
    }
}
